﻿/*
 * Created by SharpDevelop.
 * User: dol
 * Date: 16/6/2556
 * Time: 10:37
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections;
using System.Collections.Generic ;
using System.Drawing;

namespace titi.utilmouse
{
	/// <summary>
	/// Description of MouseMath.
	/// </summary>
	sealed public class MouseMath
	{
		public MouseMath()
		{
		}
		public List<Point> GetPointsInLine(Point a , Point b){
			List<Point> ps = new List<Point>();
			double len = CalcLength(a,b);
			int ilen = (int)len ;
			for(int i = 0 ; i <= ilen  ; i++){
				Point p = CalculatePointAtDistance(a,b,i);
				ps.Add(p);
			}
			return ps ;
		}
		/**
		 *  //REF: http://stackoverflow.com/questions/12550365/calculate-a-point-along-the-line-a-b-at-a-given-distance-from-a
		 * 
		 */
	    public Point CalculatePointAtDistance(Point a, Point b, int distance)
		{
		
		        // a. calculate the vector from o to g:
		        double vectorX = b.X - a.X;
		        double vectorY = b.Y - a.Y;
		
		        // b. calculate the proportion of hypotenuse
		        double factor = distance / Math.Sqrt(vectorX * vectorX + vectorY * vectorY);
		
		        // c. factor the lengths
		        vectorX *= factor;
		        vectorY *= factor;
		
		        // d. calculate and Draw the new vector,
		        return new Point((int)(a.X + vectorX), (int)(a.Y + vectorY));
		}
	    public double CalcLength(Point a , Point b){
	    	double z2 =  Math.Pow(a.X - b.X,2) + Math.Pow(a.Y-b.Y ,2 ) ;
	    	return Math.Sqrt(z2);
	    }
	}
}
